<template>
  <div class="headercontent">
    <div class="contentWeb">
      <div class="hearTop">
        <div class="logo"></div>
        <div class="search">
          <el-select
            v-model="zhiwei"
            @change="changezhiwei"
            :style="'width:'+ (['job', 'company', 'findUser'].includes(zhiwei) ? 80 : 120) +'px;'"
            class="xiala">
            <el-option
              v-for="item in typelist"
              :key="item.name"
              :label="item.title"
              :value="item.name">
            </el-option>
          </el-select>
          <div class="inputtext"><input v-model="winsearchtitle" placeholder="请按关键字进行搜索"/></div>
          <button class="searchbtn" @click="seatchwin">搜索</button>

        </div>
        <div class="loginStatus" v-if="!isLogin">
          <span @click="qidong('reg')">注册</span>
          <span class="sx"> </span>
          <span href="#" @click="qidong('login')">登录</span>
        </div>
        <div class="loginStatus" v-if="isLogin">
          <span @click="exit">退出</span>
          <template v-if="shenfen == 1">
            <span style="color: #12cde5" v-if="companyInfo.approval == 2"><i class="el-icon-user-solid"></i>{{ md_userInfo.nickname || '' }}</span>
            <span style="color: #c60000" @click.stop="showAudit = true" v-else-if="companyInfo.approval == 1"><i class="el-icon-user-solid"></i>{{ md_userInfo.nickname }}审核中</span>
            <span style="color: #c60000" @click.stop="showAudit = true" v-else-if="companyInfo.approval == 3"><i class="el-icon-user-solid"></i>{{ md_userInfo.nickname }}未通过</span>
          </template>
          <template v-else>
            <span style="color: #12cde5" v-if="md_userInfo.elAppls == 2"><i class="el-icon-user-solid"></i>{{ md_userInfo.nickName || md_userInfo.phone }}</span>
            <span style="color: #c60000" @click.stop="showPersonAudit = true" v-else-if="md_userInfo.elAppls == 1"><i class="el-icon-user-solid"></i>{{ md_userInfo.nickName || md_userInfo.phone }}审核中</span>
            <span style="color: #c60000" @click.stop="showPersonAudit = true" v-else-if="md_userInfo.elAppls == 3"><i class="el-icon-user-solid"></i>{{ md_userInfo.nickName || md_userInfo.phone }}未通过</span>
          </template>
        </div>
        <div class="clear"></div>
      </div>
      <ul class="nav clear" v-if="shenfen == 2">
        <li v-for="(item, index) in navlist" :key="index" :class="notab == item.name ? 'on': ''">
          <span @click="tourl(item.url)">{{ item.title }}</span>
        </li>
      </ul>
      <ul class="nav clear" v-if="shenfen == 1">
        <li v-for="(item, index) in navlist2" :key="index" :class="notab == item.name ? 'on': ''">
          <span @click="tourl(item.url)">{{ item.title }}</span>
        </li>
      </ul>
    </div>
    <div class="showLogintype">
      <el-dialog :close-on-click-modal="false" :close="closedio" :visible.sync="showLogintype" width="800px">
        <div class="Logintype">
          <div class="titles">选择{{ tx }}身份</div>
          <div class="clear">
            <div class="mokuai" @click="shfenclick(2)">
              <img src="../assets/img/gerens.png">
              <h2>个人业务</h2>
            </div>
            <div class="mokuai" @click="shfenclick(1)">
              <img src="../assets/img/qiyes.png">
              <h2>企业业务</h2>
            </div>
          </div>
        </div>
      </el-dialog>
    </div>
    <el-dialog
      :close-on-click-modal="false"
      :close="closelogin"
      :visible.sync="showLogin"
      width="650px">
      <div class="Logins">
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane label="账号登录" name="0">
            <el-alert :title="phoneError" type="error" v-if="phoneError" :closable="false"></el-alert>
            <el-form ref="form" :model="zhinfo" style="margin-top: 40px;" label-width="0">
              <el-form-item>
                <el-input v-model="zhinfo.account" @input="phoneError = ''" placeholder="账号"></el-input>
              </el-form-item>
              <el-form-item prop="pass" style="margin-top: 10px;">
                <el-input
                  type="password"
                  placeholder="密码"
                  v-model="zhinfo.password"
                  @input="phoneError = ''"
                  autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item prop="zhVCode" style="margin-top: 10px;">
                <el-input placeholder="请输入图片验证码" v-model="zhinfo.vcode" style="width: 370px"/>
                    <div style="margin-left: 20px;
                      width: 130px;
                      height: 40px;
                      border: 1px solid #f5f5f5;
                      display: inline-block;
                      margin-top: 0px;
                      display:inline-block">
                      <Captch height="40px" @update="zhCaptchValue"></Captch>
                    </div>
              </el-form-item>
              <el-form-item style="margin-top: 30px; margin-bottom: 0px;">
                <el-button type="primary" class="btns" style="width: 100%" @click="zhSubmit">登录
                </el-button>
              </el-form-item>
              <el-form-item>
                <el-checkbox label="下次自动登录" style="float: left" name="type"></el-checkbox>
                <div style="float: right;">
                  <span style="margin-right: 10px; cursor: pointer;" @click="forgetclick">忘记密码</span>|<span
                    style="margin-left: 10px; cursor: pointer;"
                    @click="regclick">注册</span>
                </div>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="手机号登录" name="1">
            <el-alert :title="phoneError" type="error" v-if="phoneError" :closable="false"></el-alert>
            <el-form ref="form" :model="dxinfo" style="margin-top: 40px;" label-width="0">
              <el-form-item>
                <el-input
                  v-model="dxinfo.mobileNum"
                  placeholder="手机号"
                  maxlength="11"
                  :disabled="disabled"
                  @input="phoneError = ''"></el-input>

              </el-form-item>
              <el-form-item prop="pass" style="margin-top: 10px;">
                <el-input
                  placeholder="验证码"
                  v-model="dxinfo.verifyCode"
                  @input="verifySms"
                  maxlength="6"
                  style="width: 220px; margin-right: 20px; display: inline-block; float: left;"></el-input>
                <el-button
                  :disabled="sendCode > 0 ? true: false"
                  @click="sendSms"
                  style="width: 30%; margin-left: 5%; float: left;"
                  type="primary">{{ sendCode ?
                    sendCode+'秒后可再次获取' : '点击获取验证码' }}
                </el-button>
                <!-- <div class="yzms"></div> -->
              </el-form-item>
              <el-form-item style="margin-top: 30px; margin-bottom: 0px;">
                <el-button type="primary" class="btns" style="width: 100%" @click="dxSubmit">登录
                </el-button>
              </el-form-item>
              <el-form-item>
                <el-checkbox label="下次自动登录" style="float: left" name="type"></el-checkbox>
                <div style="float: right;">
                  <span style="margin-right: 10px; cursor: pointer;" @click="forgetclick">忘记密码</span>|<span
                    style="margin-left: 10px; cursor: pointer;"
                    @click="regclick">注册</span>
                </div>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="身份证号登录" name="2">
            <el-form ref="form" :model="sfinfo" style="margin-top: 40px;" label-width="0">
              <el-form-item>
                <el-input
                  placeholder="身份证号"
                  style="width: 70%"
                  id="certNumber"
                  v-model="sfinfo.identifyCode"></el-input>
                <el-button @click="duqu" style="width: 25%; margin-left: 5%" type="primary">读取身份信息
                </el-button>
              </el-form-item>
              <el-form-item prop="pass" style="margin-top: 10px;">
                <el-input
                  placeholder="密码"
                  type="password"
                  v-model="sfinfo.password"
                  autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item prop="sfVCode" style="margin-top: 10px;">
                <el-input placeholder="请输入图片验证码" v-model="sfinfo.vcode" style="width: 370px"/>
                    <div style="margin-left: 20px;
                      width: 130px;
                      height: 40px;
                      border: 1px solid #f5f5f5;
                      display: inline-block;
                      margin-top: 0px;
                      display:inline-block">
                      <Captch height="40px" @update="sfCaptchValue"></Captch>
                    </div>
              </el-form-item>
              <el-form-item style="margin-top: 30px; margin-bottom: 0px;">
                <el-button type="primary" class="btns" style="width: 100%" @click="sfSubmit">登录
                </el-button>
              </el-form-item>
              <el-form-item>
                <el-checkbox label="下次自动登录" style="float: left" name="type"></el-checkbox>
                <div style="float: right;">
                  <span style="margin-right: 10px; cursor: pointer;" @click="forgetclick">忘记密码</span>|<span
                    style="margin-left: 10px; cursor: pointer;"
                    @click="regclick">注册</span>
                </div>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane v-if="showScanTab" label="二维码登录" name="3">
            <div style="width: 0px;height: 0px;">
              <el-input
                placeholder="二维码信息"
                style="width:0px;height: 0px;margin-left: 20px;"
                ref="mark"
                v-model="scanValue"></el-input>
            </div>

            <el-alert :title="QRError" type="error" v-if="QRError" :closable="false"></el-alert>
            <el-alert type="error" title="" :closable="false" style="background-color: white;"></el-alert>

            <img style="width: 400px;height: 300px;" src="../assets/img/QR.png" />
          </el-tab-pane>
        </el-tabs>
      </div>
    </el-dialog>
    <div style="height: 0; width: 0; overflow: hidden;">
      <p id="cert_message" style="display: none;"></p>
      <p id="cert_message_type" style="display: none;"></p>
      <table class="pTableStyle">
        <caption style="margin-bottom:5px"><h2 style="text-align: center">读取身份证信息</h2></caption>
        <tr>
          <td>
            <table class="tableStyle">
              <tr>
                <td>
                  <label>姓名</label>
                </td>
                <td>
                  <input readonly="readonly" type="text" value="" id="personName"/>
                </td>
                <td>
                  <label>出生日期</label>
                </td>
                <td>
                  <input readonly="readonly" type="text" value="" id="birthday"/>
                </td>
              </tr>
              <tr>
                <td>
                  <label>性别</label>
                </td>
                <td>
                  <input readonly="readonly" type="text" value="" id="gender"/>
                </td>
                <td>
                  <label>证件号码</label>
                </td>
                <td>
                </td>
              </tr>
              <tr>
                <td>
                  <label>民族</label>
                </td>
                <td>
                  <input readonly="readonly" type="text" value="" id="nation"/>
                </td>
                <td>
                  <label>签发机关</label>
                </td>
                <td>
                  <input readonly="readonly" type="text" value="" id="idIssued"/>
                </td>
              </tr>

              <tr>
                <td>
                  <label>住址</label>
                </td>
                <td colspan="3">
                  <input readonly="readonly" type="text" value="" id="address" style="width:95.5%"/>
                </td>
              </tr>
              <tr>
                <td>
                  <label>有效期限</label>
                </td>
                <td>
                  <input readonly="readonly" type="text" value="" id="issuedValidDate"/>
                </td>
              </tr>
            </table>
          </td>
          <td>
            <div class="floatL">
              <div id="localImag">
                <img
                  width="120px"
                  height="140px"
                  src="state/images/userImage.png"
                  onerror="this.src='images/userImage.png'"
                  style="margin-left:5px"
                  id="id_img_pers">
                <br/>
                <span>(尺寸大小120×140)</span>
              </div>
            </div>
          </td>
        </tr>
      </table>
    </div>

    <!-- 个人审核状态弹框 -->
    <el-dialog
      :close-on-click-modal="false"
      :before-close="closeAudit"
      :visible.sync="showPersonAudit"
      width="800px"
      class="header-audit">
      <div slot="title"> 审核详情</div>
      <div class="header-audit-top">
        <img
          :src="md_userInfo.elAppls == 1 ? require('../assets/img/company_auditing.png'): require('../assets/img/audit_error.png')"
          class="img"> {{ md_userInfo.elAppls == 1 ? '您的注册信息正在审核中': '您的注册信息未通过审核' }}
      </div>
      <div v-if="md_userInfo.elAppls == 3" class="header-audit-nopass" style="width:100%">
        <span class="res">未通过原因</span>
        <span class="msg">{{ md_userInfo.elJzyy }}</span>
      </div>
      <div class="header-audit-body">
        <div class="block">
          <div class="info-left">
            <div style="font-size: 28px; color: #1e1e1e; line-height: 50px;">{{ md_userInfo.nickName }}</div>
          </div>
          <img
            :src="md_userInfo.elAppls == 1 ? require('../assets/img/auditing_img.png'): require('../assets/img/audit_false.png')"
            class="info-right"
            alt="">
        </div>
        <div class="block" style="flex-direction: column; padding-bottom: 20px">
          <div class="cell">
            <div class="left">身份证号码：</div>
            <div class="right">{{ md_userInfo.identifyCode }}</div>
          </div>
          <div class="cell">
            <div class="left">手机号：</div>
            <div class="right">{{ md_userInfo.mobileNum }}</div>
          </div>
        </div>
        <div class="block" style="flex-direction: column;">
          <div class="cell">
            <div class="left">身份证正面：</div>
            <div class="right">
              <img @click="showImage(md_userInfo.sfzZm)" :src="md_userInfo.sfzZm" class="img" alt="">
            </div>
          </div>
          <div class="cell">
            <div class="left">身份证反面：</div>
            <div class="right">
              <img @click="showImage(md_userInfo.sfzZm)" :src="md_userInfo.sfzFm" class="img" alt="">
            </div>
          </div>
        </div>
      </div>
      <div v-if="md_userInfo.elAppls == 3" style="padding-bottom:30px">
        <el-button
          type="primary"
          class="btns"
          style="background: #20a2b2;
                      width: 300px;
                      font-size: 18px;
                      border: 0;
                      border-radius: 7px;"
          @click="reUserRegister">重新注册</el-button>
        <el-button
          class="btns"
          style=" width: 300px;
                        font-size: 18px;
                        margin-left: 30px;
                        background: #f6f6f8;
                        border: 1px solid #dcdcdc;
                        border-radius: 7px;"
          @click="delRegInfo">注销注册信息</el-button>
      </div>
      <el-dialog
        width="600px"
        :visible.sync="innerVisible"
        append-to-body>
        <img
          :src="bigImageUrl"
          style="width: 550px;"
          alt="">
      </el-dialog>
    </el-dialog>

    <!-- 企业审核状态弹框 -->
    <el-dialog
      :close-on-click-modal="false"
      :before-close="closeAudit"
      :visible.sync="showAudit"
      width="1200px"
      class="header-audit">
      <div slot="title"> 审核详情</div>
      <div class="header-audit-top">
        <img
          :src="companyInfo.approval == 1 ? require('../assets/img/company_auditing.png'): require('../assets/img/audit_error.png')"
          class="img"> {{ companyInfo.approval == 1 ? '您的注册信息正在审核中': '您的注册信息未通过审核' }}
      </div>
      <div v-if="companyInfo.approval == 3" class="header-audit-nopass">
        <span class="res">未通过原因</span>
        <span class="msg">{{ companyInfo.jzyy }}</span>
      </div>
      <div class="header-audit-body">
        <div class="block">
          <div class="info-left">
            <div style="font-size: 28px; color: #1e1e1e; line-height: 50px;">{{ companyInfo.name }}</div>
            <div style="font-size: 16px; color: #8d8e9c; line-height: 20px;"> {{ companyInfo.industry }} <span
              style="margin: 0 10px;">|</span> {{ companyInfo.enterpriseNature }} <span
              style="margin: 0 10px;">|</span> {{ companyInfo.companySize }}
            </div>
            <div style="font-size: 18px; color: #505050; line-height: 24px; margin-top: 20px;font-family: MicrosoftYaHei;">
              <img
                src="../assets/img/address.png"
                style="width: 16px; margin-right: 5px;float: left;"
                alt="">
              {{ companyInfo.addressDetail }}
            </div>
          </div>
          <img
            :src="companyInfo.approval == 1 ? require('../assets/img/auditing_img.png'): require('../assets/img/audit_false.png')"
            class="info-right"
            alt="">
        </div>
        <div class="block">
          <div class="item" style="width:60%">
            <div class="item-row">
              <label>企业简称：</label><span>{{ companyInfo.nickname }}</span>
            </div>
            <div class="item-row">
              <label>统一社会信用代码：</label><span>{{ companyInfo.sociologyCreditCode }}</span>
            </div>
            <div class="item-row">
              <label>所属行业：</label>
              <span style="line-height:22px">{{ companyInfo.industry }}</span>
            </div>
            <div class="item-row">
              <label>企业性质：</label><span>{{ companyInfo.enterpriseNature }}</span>
            </div>
          </div>
          <div class="item">
            <div class="item-row">
              <label>招聘联系人：</label><span>{{ companyInfo.contacts }}</span>
            </div>
            <div class="item-row">
              <label>身份证号：</label><span>{{ companyInfo.identifyCode }}</span>
            </div>
            <div class="item-row">
              <label>手机号：</label><span>{{ companyInfo.mobileNum }}</span>
            </div>
            <div class="item-row">
              <label>电子邮箱：</label><span>{{ companyInfo.email }}</span>
            </div>
          </div>
        </div>
        <div class="block" style="flex-direction: column;">
          <div class="cell">
            <div class="left">企业介绍：</div>
            <div class="right">{{ companyInfo.introduction }}</div>
          </div>
          <div class="cell">
            <div class="left">企业福利：</div>
            <div class="right">
              <el-tag
                type="warning"
                :key="tag"
                v-for="tag in fuli"
                style="margin-right: 10px;"
                :disable-transitions="false"
                @close="handleClose(tag)">
                {{ tag }}
              </el-tag>
            </div>
          </div>
          <div class="cell">
            <div class="left">工作时间：</div>
            <div class="right">{{ companyInfo.startWorkTime }}-{{ companyInfo.endWorkTime }}</div>
          </div>
          <div class="cell">
            <div class="left">经办人身份证明：</div>
            <div class="right">
              <img @click="showImage(companyInfo.jbrsfzm)" :src="companyInfo.jbrsfzm" class="img" alt="">
            </div>
          </div>
          <div class="cell">
            <div class="left">用人单位委托证明：</div>
            <div class="right">
              <img @click="showImage(companyInfo.yrdwwtzm)" :src="companyInfo.yrdwwtzm" class="img" alt="">
            </div>
          </div>
          <div class="cell">
            <div class="left">营业执照：</div>
            <div class="right">
              <img @click="showImage(companyInfo.businessLicenseUrl)" :src="companyInfo.businessLicenseUrl" class="img" alt="">
            </div>
          </div>
          <div class="cell">
            <div class="left">企业法人身份证：</div>
            <div class="right">
              <img @click="showImage(companyInfo.sfzZm)" :src="companyInfo.sfzZm" class="img" alt="">
              <img @click="showImage(companyInfo.sfzFm)" :src="companyInfo.sfzFm" class="img" alt="">
            </div>
          </div>
        </div>
      </div>

      <div v-if="companyInfo.approval == 3" style="padding-bottom:30px">
        <el-button
          type="primary"
          class="btns"
          style="background: #20a2b2;
                      width: 300px;
                      font-size: 18px;
                      border: 0;
                      border-radius: 7px;"
          @click="reRegister">重新注册</el-button>
        <el-button
          class="btns"
          style=" width: 300px;
                        font-size: 18px;
                        margin-left: 30px;
                        background: #f6f6f8;
                        border: 1px solid #dcdcdc;
                        border-radius: 7px;"
          @click="delRegInfo">注销注册信息</el-button>
      </div>
      <el-dialog
        width="600px"
        :visible.sync="innerVisible"
        append-to-body>
        <img
          :src="bigImageUrl"
          style="width: 550px;"
          alt="">
      </el-dialog>
    </el-dialog>
  </div>
</template>
<script type="text/babel">
// @ is an alias to /src
import {
  login,
  loginCompany,
  CVBaseInfo,
  // getUserByUid,
  EnterpriseInfo,
  sendMessage,
  GetQueryString,
  mobileLogin,
  userIdLogin,
  qrLogin,
  CompanyMobileLogin,
  CompanyIdLogin,
  CompanyRegisterDelete
  // getSensWords
} from '../assets/js/domains'
import logo from '../assets/img/logo.png'
import Element from 'element-ui'
import Captch from './captch.vue'
import util from '../assets/js/util'

export default {
  name: 'Header',
  components: {Captch},
  props: {
    notab: {
      default: 'index'
    }
  },
  data () {
    return {
      QRError: '',
      winsearchtitle: '',
      fuli: [],
      showScanTab: false,
      disabled: false,
      scanValue: '',
      qidongStatus: '',
      zhVCode:'',
      sfVCode:'',
      zhinfo: {},
      sfinfo: {},
      dxinfo: {},
      phoneError: '',
      activeName: 0,
      showLogintype: false,
      showLogin: false,
      showAudit: false,
      showPersonAudit: false,
      innerVisible: false,
      bigImageUrl: '',
      typelist: [{
        value: 1,
        title: '职位',
        name: 'job'
      }, {
        value: 2,
        title: '企业',
        name: 'company'
      }, {
        value: 3,
        title: '本地信息',
        name: 'localNews'
      }, {
        value: 4,
        title: '职场资讯',
        name: 'jobNews'
      }],
      // typelist: [{
      //   value: 1,
      //   title: '职位',
      //   name: 'job'
      // }, {
      //   value: 2,
      //   title: '企业',
      //   name: 'company'
      // }],
      zhiwei: 'job',
      navlist: [
        {
          name: 'index',
          title: '首页',
          url: 'index.html'
        },
        {
          name: 'company',
          title: '企业库',
          url: 'company.html'
        },
        {
          name: 'job',
          title: '找工作',
          url: 'job.html'
        }, {
          name: 'join',
          title: '招聘会',
          url: 'join.html'
        },
        {
          name: 'localNews',
          title: '本地信息',
          url: 'localNews.html'
        },
        {
          name: 'jobNews',
          title: '职场资讯',
          url: 'jobNews.html'
        },
        {
          name: 'member',
          title: '个人中心',
          url: 'member.html'
        }
      ],
      navlist2: [
        {
          name: 'index',
          title: '首页',
          url: 'index.html'
        },
        {
          name: 'findUser',
          title: '找人才',
          url: 'findUser.html'
        },
        {
          name: 'join',
          title: '招聘会',
          url: 'join.html'
        },
        {
          name: 'localNews',
          title: '本地信息',
          url: 'localNews.html'
        },
        {
          name: 'jobNews',
          title: '职场资讯',
          url: 'jobNews.html'
        },
        {
          name: 'companyCenter',
          title: '企业中心',
          url: 'companyCenter.html'
        }
      ],
      isLogin: false,
      logo: logo,
      shenfen: 2,
      user_uid: '',
      md_userInfo: {},
      companyInfo: {},
      smsCode: '',
      sendCode: 0,
      tx: '登录'
    }
  },
  watch: {
    // 监听Tab
    activeName (value) {
      // 获取焦点
      const that = this

      if (value === 3) {
        that.QRError = '请将您的二维码对准扫描窗口！'
        setTimeout(function () {
          that.$refs.mark.focus()
        }, '500')
      }
    },
    scanValue (newValue) {
      if (newValue === '') {
        return
      }
      const value = newValue.substring(newValue.length - 2, newValue.length)
      // 判断是否输入完

      if (value !== '|M') {
        this.QRError = '二维码无效，请出示正确的二维码信息！'
        return
      }
      // 分割
      const data = newValue.split('|')
      if (data.length !== 4) {
        this.QRError = '二维码无效，请出示正确的二维码信息！'
        this.scanValue = ''
        return
      }
      // 获取当前时间戳
      const endDate = Date.parse(new Date())
      // 获取开始的时间戳
      const startDate = data[2]
      // 获取时间差(秒)
      const difference = (endDate - startDate) / 1000
      if (difference > 60) {
        this.QRError = '二维码已过期，请刷新二维码重新登录！'
        this.scanValue = ''
        return
      }
      // 密码
      const pass = data[1]
      // 身份证号
      const str = data[0]
      // 拆分数组
      const array = []
      // 数组下标
      let index = 0
      // 循环拆解
      for (var i = 0; i < str.length - 1; i++) {
        // 每组3个字符串
        array[index] = str.substring(i, i + 3)
        // 下标+1
        index++
        // 下一次从i+2位开始
        i = i + 2
      }
      // 复原顺序
      const num = [3, 1, 4, 2, 5, 0]
      // 正序
      let just = ''
      // 循环取正序
      for (var j = 0; j < array.length; j++) {
        // 按正顺序取
        just += array[num[j]]
      }

      const that = this
      if (that.shenfen * 1 === 2) {
        that.scanLogin(just, util.strEncode(pass))
        // that.scanLogin(just, pass);
      } else {
        // const sfinfo = Object.assign({}, that.sfinfo)
        // sfinfo.identifyCode = just
        // sfinfo.password = util.strEncode(pass)
        // sfinfo.password = pass
        that.scanLogin(just, util.strEncode(pass))
        // login.then(function (res) {
        // if (that.shenfen == 2) {
        // if(!res.data.userUid){
        // that.QRError = '登录信息不正确,请重新扫码登录';
        // that.scanValue = '';
        // return;
        // }
        //     }else{
        // if (!res.data.enterpriseUid) {
        // that.QRError = '登录信息不正确,请重新扫码登录';
        // that.scanValue = '';
        // return;
        // }
        //     }
        // that.QRError = res.msg;
        // that.scanValue = '';
        //   that.successDeal(res)
        // }).catch(function (e) {
        //   that.$alert('登录失败', '提示', {
        //     confirmButtonText: '确定',
        //     callback() {
        //       window.location.href = 'index.html'
        //     }
        //   })
        // })
      }
    }
  },
  computed: {},
  created () {
    // this.getSensWords()
    if (localStorage.getItem('shenfen')) {
      this.shenfen = localStorage.getItem('shenfen')
    }
    if (localStorage.getItem('md_user_uid')) {
      this.user_uid = localStorage.getItem('md_user_uid')
      // this.auditCheck({id: this.user_uid })
    }
    if (localStorage.getItem('zhiweitype')) {
      this.zhiwei = localStorage.getItem('zhiweitype')
    }
    if (localStorage.getItem('winsearchtitle') && GetQueryString('title')) {
      this.winsearchtitle = localStorage.getItem('winsearchtitle')
    }
    window.startISSonlineDevice((result) => {
      console.log('startISSonlineDevice', result)
      this.showScanTab = true
    })
  },
  mounted () {
    if (localStorage.getItem('showlogin') === 1) {
      this.showLogin = true
      this.activeName = 0
      localStorage.setItem('showlogin', '')
    }
    if (this.shenfen * 1 === 2 && this.user_uid) {
      this.getCVBaseInfo()

      if (!localStorage.getItem('zhiweitype')) {
        this.zhiwei = 'job'
        localStorage.setItem('zhiweitype', 'job')
      }
    }
    if (this.shenfen * 1 === 1 && this.user_uid) {
      this.getEnterpriseInfo()
      if (!localStorage.getItem('zhiweitype')) {
        localStorage.setItem('zhiweitype', 'findUser')
        this.zhiwei = 'findUser'
      }
      this.typelist = [{
        value: 1,
        title: '人才',
        name: 'findUser'
      }, {
        value: 2,
        title: '本地信息',
        name: 'localNews'
      }, {
        value: 3,
        title: '职场资讯',
        name: 'jobNews'
      }]
    }
  },
  methods: {
    scanLogin (identifyCode, password) {
      qrLogin({ identifyCode, password }).then(res => {
        if (res.code === 200) {
          if (this.shenfen === 2) {
            if (!res.data.userUid) {
              this.QRError = '登录信息不正确,请重新扫码登录'
              this.scanValue = ''
              return
            }
          } else {
            this.successDeal(res)
            if (!res.data.enterpriseUid) {
              this.QRError = '登录信息不正确,请重新扫码登录'
              this.scanValue = ''
              return
            }
          }
          this.QRError = res.msg
          this.successDeal(res)
        } else {
          this.QRError = res.msg + ',请重新扫码登录'
          this.scanValue = ''
          this.$refs.mark.focus()
        }
      })
    },
    showImage (imgUrl) {
      this.innerVisible = true
      this.bigImageUrl = imgUrl
    },
    sfCaptchValue(e){
      this.sfVCode = e
    },
    zhCaptchValue(e){
      this.zhVCode = e
    },
    reUserRegister () {
      const uid = localStorage.getItem('md_user_uid')
      window.location.href = '/userReg.html?uid=' + uid
    },
    reRegister () {
      const euid = localStorage.getItem('md_user_uid')
      window.location.href = '/companyReg.html?euid=' + euid
    },
    delRegInfo () {
      const userInfo = JSON.parse(localStorage.getItem('md_userInfo'))
      if (!userInfo) return
      CompanyRegisterDelete({ delete_id: userInfo.id }).then(res => {
        if (res.code === 200) {
          this.$message.success('注销成功！')
          localStorage.clear()
          setTimeout(() => {
            window.location.href = '/index.html'
          }, 3000)
        } else {
          this.$message.error(res.message || '信息注销失败！')
        }
      })
    },
    onClickNoPass () {
      this.showAudit = true
    },
    changezhiwei (e) {
      this.zhiwei = e
      localStorage.setItem('zhiweitype', e)
    },
    seatchwin () {
      localStorage.setItem('winsearchtitle', this.winsearchtitle)
      window.location.href = this.zhiwei + '.html?title=' + encodeURI(encodeURI(this.winsearchtitle))
    },
    tourl (url) {
      if (url !== 'member.html' && url !== 'companyCenter.html') {
        window.location.href = url
      } else {
        if (this.user_uid) {
          window.location.href = url
        } else {
          this.$alert('您还没有登录', '提示', {
            confirmButtonText: '确定',
            callback () {
              window.location.href = 'index.html'
            }
          })
        }
      }
    },
    exit () {
      localStorage.clear()
      window.location.href = 'index.html'
    },
    getEnterpriseInfo () {
      const _this = this
      EnterpriseInfo({ enterprise_id: this.user_uid }).then(function (res) {
        if (res.code === 200) {
          _this.companyInfo = res.data
          res.data.treatment && (_this.fuli = res.data.treatment.split(',').filter(item => !!item.trim()))
          _this.isLogin = true
          if (localStorage.getItem('md_userInfo')) {
            _this.md_userInfo = JSON.parse(localStorage.getItem('md_userInfo'))
            _this.md_userInfo.approval = _this.companyInfo.approval
            _this.md_userInfo.addressDetail = _this.companyInfo.addressDetail
            _this.md_userInfo = Object.assign({}, _this.md_userInfo)
            localStorage.setItem('md_userInfo', JSON.stringify(_this.md_userInfo))
          }
        }
      })
    },
    getCVBaseInfo () {
      const _this = this
      const curUserInfo = JSON.parse(localStorage.getItem('md_userInfo'))
      const reg = /^(\d{3})\d{4}(\d{4})$/
      curUserInfo.phone = curUserInfo.mobileNum.replace(reg, '$1****$2')
      CVBaseInfo({ user_uid: this.user_uid }).then(res => {
        if (res.code !== 200) {
          _this.isLogin = false
          return
        }
        _this.isLogin = true

        if (res.data && curUserInfo) {
          curUserInfo.jlzt = res.data.jlzt
          curUserInfo.realName = res.data.name
          curUserInfo.nickName = res.data.name
          curUserInfo.elAppls = res.data.elAppls
          curUserInfo.elJzyy = res.data.elJzyy
          this.md_userInfo = curUserInfo
          localStorage.setItem('md_userInfo', JSON.stringify(curUserInfo))
        }
      })
    },
    duqu () {
      var that = this
      new Device().startFun(function (type, message) {
        that.showMessage(type, message)
      })
    },
    showMessage (type, message) {
      if (undefined !== this.loading) this.loading.close()
      if (type !== 'loading') {
        Element.MessageBox(message, '', type)
      } else {
        this.loading = this.$loading({
          lock: true,
          text: message,
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        })
      }
    },
    closelogin () {
      this.showLogin = false
    },
    closedio () {
      this.showLogintype = false
    },
    qidong (item) {
      this.qidongStatus = item
      if (item === 'reg') {
        this.tx = '注册'
      } else {
        this.tx = '登录'
      }
      window.startISSonlineDevice((result) => {
        this.showScanTab = true
      })
      this.showLogintype = true
    },
    regclick () {
      if (this.shenfen === 2) {
        window.location.href = 'userReg.html'
      } else {
        window.location.href = 'companyReg.html'
      }
    },
    forgetclick () {
      window.location.href = 'forgetPwd.html?sf=' + this.shenfen
    },
    handleClick () {
    },
    shfenclick (e) {
      const that = this
      this.shenfen = e
      this.showLogintype = false
      if (this.qidongStatus === 'login') {
        this.showLogin = true
      } else {
        if (this.shenfen === 2) {
          window.location.href = 'userReg.html'
        } else {
          window.location.href = 'companyReg.html'
        }
      }
      setTimeout(function () {
        that.QRError = '请将您的二维码对准扫描窗口！'
        that.scanValue = ''
        that.$refs.mark.focus()
      }, '500')
    },
    zhSubmit () {
      const _this = this
      if (_this.zhinfo.account === '' || !_this.zhinfo.account) {
        this.phoneError = '请输入账号'
        return false
      } else {
        this.phoneError = ''
      }
      if (_this.zhinfo.password === '' || !_this.zhinfo.password) {
        this.phoneError = '请输入密码'
        return false
      } else {
        this.phoneError = ''
      }
      if (!this.zhinfo.vcode) {
        this.phoneError = '请输入图片验证码'
        return false
      } else {
        this.phoneError = ''
      }
      if (this.zhVCode != this.zhinfo.vcode.toUpperCase()) {
        this.phoneError = '请输入正确的图片验证码'
        return
      } else{
        this.phoneError = ''
      }
      const formData = Object.assign({}, _this.zhinfo)
      formData.password = util.strEncode(formData.password)
      let loginFn = null
      if (_this.shenfen === 2) {
        loginFn = login(formData)
      } else {
        loginFn = loginCompany(formData)
      }
      loginFn.then(function (res) {
        _this.successDeal(res)
      }).catch(function (e) {
        _this.$alert('登录失败', '提示', {
          confirmButtonText: '确定',
          callback () {
            window.location.href = 'index.html'
          }
        })
      })
    },
    auditCheck (data) {
      var _this = this
      this.showLogin = false
      EnterpriseInfo({ enterprise_id: data.id }).then(function (res) {
        _this.isLogin = true
        if (res.code === 200) {
          data = res.data
          if (data.approval === 2) {
            window.location.href = 'index.html'
            return false
          }

          // data.startWorkTime = moment(data.startWorkTime).format('HH:mm')
          // data.endWorkTime = moment(data.endWorkTime).format('HH:mm')
          _this.companyInfo = data
          data.treatment && (_this.fuli = data.treatment.split(',').filter(item => !!item.trim()))
          _this.showAudit = true
          if (localStorage.getItem('md_userInfo')) {
            _this.md_userInfo = JSON.parse(localStorage.getItem('md_userInfo'))
            _this.md_userInfo = Object.assign({}, _this.md_userInfo)
          }
        }
      })
      return false
    },
    closeAudit () {
      window.location.href = 'index.html'
    },
    sendSms () {
      var _this = this
      if (undefined === this.dxinfo.mobileNum || this.dxinfo.mobileNum === '' || /(13\d|14[579]|15[^4\D]|17[^49\D]|18\d)\d{8}/g.test(this.dxinfo.mobileNum) === false) {
        this.phoneError = '手机号不存在'
        return
      }
      console.log('mobile check success! start send sms')
      sendMessage({ phoneNumber: this.dxinfo.mobileNum }).then(function (res) {
        console.log(res)
        if (res.code === 200) {
          _this.$message.success('验证码发送成功')
          _this.sendCodeInterval()
          _this.smsCode = res.data
          _this.disabled = true
        }
      })
    },
    sendCodeInterval () {
      this.sendCode = 60
      var _this = this
      var intervalHanlder = setInterval(function () {
        _this.sendCode -= 1
        if (_this.sendCode <= 0) {
          clearInterval(intervalHanlder)
        }
      }, 1000)
    },
    verifySms () {
      if (this.dxinfo.verifyCode.length === 6 && this.dxinfo.verifyCode !== this.smsCode) {
        this.phoneError = '短信验证码输入不正确'
      } else {
        this.phoneError = ''
      }
    },
    sfSubmit () {
      const _this = this
      var login = null
      if (!this.sfinfo.identifyCode) {
        this.$message.error('请输入身份证号码')
        return
      }
      if (!this.sfinfo.password) {
        this.$message.error('请输入密码')
        return
      }
      if (!this.sfinfo.vcode) {
        this.$message.error('请输入图片验证码')
        return
      }
      if (this.sfVCode != this.sfinfo.vcode.toUpperCase()) {
        this.$message.error('请输入正确的图片验证码')
        return
      }
      const sfinfo = Object.assign({}, this.sfinfo)
      sfinfo.password = util.strEncode(sfinfo.password)
      if (this.shenfen * 1 === 2) {
        login = userIdLogin(sfinfo)
      } else {
        login = CompanyIdLogin(sfinfo)
      }
      login.then(function (res) {
        _this.successDeal(res)
      }).catch(function (e) {
        _this.$alert('登录失败', '提示', {
          confirmButtonText: '确定',
          callback () {
            window.location.href = 'index.html'
          }
        })
      })
    },
    dxSubmit () {
      if (this.dxinfo.mobileNum === '' || !this.dxinfo.mobileNum) {
        this.phoneError = '请输入用户手机号'
        return false
      } else {
        this.phoneError = ''
      }

      if (this.dxinfo.verifyCode === '' || !this.dxinfo.verifyCode) {
        this.phoneError = '请输入短信验证码'
        return false
      } else {
        this.phoneError = ''
      }

      if (util.isMobile(this.dxinfo.mobileNum) === false) {
        this.phoneError = '手机号不存在'
        return false
      }
      // todo
      // if (!this.dxinfo.verifyCode || this.dxinfo.verifyCode != this.smsCode) {
      //   this.phoneError = '短信验证码输入不正确'
      //   return false
      // }
      const _this = this
      var login = null
      this.dxinfo.verifyCode = undefined
      if (this.shenfen === 2) {
        login = mobileLogin(this.dxinfo)
      } else {
        login = CompanyMobileLogin(this.dxinfo)
      }
      login.then(function (res) {
        _this.successDeal(res)
      }).catch(function (e) {
        _this.$alert('登录失败', '提示', {
          confirmButtonText: '确定',
          callback () {
            window.location.href = 'index.html'
          }
        })
      })
    },
    successDeal (res) {
      const _this = this
      if (res.code === 200) {
        localStorage.setItem('shenfen', this.shenfen)
        if (this.shenfen === 2) {
          if (res.data.userUid) {
            localStorage.setItem('md_user_uid', res.data.userUid)
            localStorage.setItem('md_userInfo', JSON.stringify(res.data))
            _this.disabled = false
            this.$alert('登录成功', '提示', {
              confirmButtonText: '确定',
              callback () {
                setTimeout(() => {
                  window.location.href = 'index.html'
                }, 100)
              }
            })
          } else {
            this.$alert('登录信息不正确,请重新输入', '提示')
            _this.disabled = false
          }
        } else {
          if (res.data.enterpriseUid) {
            localStorage.setItem('md_user_uid', res.data.id)
            localStorage.setItem('md_enterpriseUid', res.data.enterpriseUid)
            localStorage.setItem('md_userInfo', JSON.stringify(res.data))
            _this.disabled = false
            this.$alert('登录成功', '提示', {
              confirmButtonText: '确定',
              callback () {
                if (_this.auditCheck(res.data)) {
                  window.location.href = 'index.html'
                }
              }
            })
          } else {
            _this.disabled = false
            this.$alert('登录信息不正确,请重新输入', '提示')
          }
        }
      } else if (res.code === 408) {
        if (!res.data.enterpriseUid) {
          this.$alert('企业用户不存在，请注册后登录', '提示')
          return
        }
        localStorage.setItem('shenfen', this.shenfen)
        localStorage.setItem('md_user_uid', res.data.id)
        localStorage.setItem('md_enterpriseUid', res.data.enterpriseUid)
        localStorage.setItem('md_userInfo', JSON.stringify(res.data))
        if (_this.auditCheck(res.data)) {
          window.location.href = 'index.html'
        }
      } else {
        this.$alert(res.msg, '提示')
      }
    }
  }
}
</script>
<style lang="less">
    @import "../assets/css/comments";
    .loginStatus{
      span{
        max-width: 145px;
        overflow: hidden;
        text-overflow:ellipsis;
        white-space: nowrap;
      }
    }
</style>
